<template>
  <el-dropdown trigger="click" @command="handleSetLocal">
    <div>
      <svg-icon class-name="size-icon" icon-class="language.svg" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-for="item of localOptions" :key="item.value" :disabled="local===item.value" :command="item.value">
        {{ item.label }}
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
export default {
  data() {
    return {
      localOptions: [
        { label: '简体中文', value: 'zh' },
        { label: 'English', value: 'en' }
      ]
    }
  },
  computed: {
    local() {
      return this.$store.getters.local
    }
  },
  methods: {
    handleSetLocal(local) {
      this.$i18n.locale = local
      this.$store.dispatch('app/setLocal', local)
      this.$message({
        message: this.$t('localSelect.text1'),
        type: 'success'
      })
      // 刷新页面
      setTimeout(() => {
        location.reload()
      }, 500)
    }
  }

}
</script>
